﻿using SBlogCore.Entitys.SystemManager;

namespace SBlogCore.WebAdminApplication.SysManager.Dto
{
    public class SysFileInfoQueryOutPut
    {
        public long? Id { get; set; }
        /// <summary>
        /// 文件存储位置（1:阿里云，2:腾讯云，3:minio，4:本地）
        /// </summary>
        public int FileLocation { get; set; }

        /// <summary>
        /// 文件仓库
        /// </summary>
        public string? FileBucket { get; set; }

        /// <summary>
        /// 文件名称（上传时候的文件名）
        /// </summary>
        public string? FileOriginName { get; set; }

        /// <summary>
        /// 文件类型
        /// </summary>
        public string? FileType { get; set; }

        /// <summary>
        /// 文件后缀
        /// </summary>
        public string? FileSuffix { get; set; }

        /// <summary>
        /// 文件大小kb
        /// </summary>
        public long FileSizeKb { get; set; }

        /// <summary>
        /// 文件大小信息，计算后的
        /// </summary>
        public string? FileSizeInfo { get; set; }

        /// <summary>
        /// 存储到bucket的名称（文件唯一标识id）
        /// </summary>
        public string? FileObjectName { get; set; }

        /// <summary>
        /// 存储路径
        /// </summary>
        public string? FilePath { get; set; }
        /// <summary>
        /// 完整路径
        /// </summary>
        public string CompletePath => $"{FileBucket}{FilePath?.Replace("\\", "/")}";

        public string Key { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public virtual DateTimeOffset? CreatedTime { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public virtual DateTimeOffset? UpdatedTime { get; set; }
        /// <summary>
        /// 是否正在使用
        /// </summary>

        public bool IsUse { get; set; } = false;
    }
    public class SysFileInfoMaps : ISblogCoreMap
    {
        public void MapDo()
        {
            TypeAdapterConfig<SysFileInfo, SysFileInfoQueryOutPut>.NewConfig()
                .Map(dest => dest.IsUse, src => src.SysFileMap!=null&&src.SysFileMap.DataId!=null)
                .Map(dest => dest.Key, src => GetMapKey(src));
        }

        private static string? GetMapKey(SysFileInfo src)
        {
            return src.SysFileMap?.Key;
        }
    }
}
